package com.joinlabs.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.joinlabs.service.IFindPwdService;
import com.joinlabs.service.IUserServiceZ;
import com.joinlabs.service.SmsService;

@Controller
@RequestMapping("/find")
@SessionAttributes(names= {"error"})
public class FindPwdAction {
	private static String annount;
	private static String yzm="00";
	@Resource
	private SmsService sms;
	
	@Resource
	private IFindPwdService updatepwd;
		
	//访问找回密码界面
	@RequestMapping("/findpwd")

	public ModelAndView reg(){
		return new ModelAndView("/findpwd/findpwd");
	}
	
	//发送短信验证
	@RequestMapping("/send")
	public void sends(HttpServletRequest request,HttpServletResponse response) {
		String tel = request.getParameter("tel");
		yzm = sms.send(tel);
		annount = tel;
//		System.out.println("甲方开具安居房就进度款加法看大家安静阿加解决就就kjj阶段空间加减速就就就就");
//		System.out.println(annount);
		
	}
	@RequestMapping("/submit")
	public ModelAndView checktel(HttpServletRequest request,HttpServletResponse response,ModelMap map) {
		String yzm1 = request.getParameter("telyzm");
		System.out.println(yzm1+yzm);
		
		if(yzm.equals(yzm1)) {
			String err = "验证成功";
		    map.addAttribute("error",err);
			return new ModelAndView("redirect:/login/suer");
		} else {
		    String err = "验证码错误";
		    map.addAttribute("error",err);
			return new ModelAndView("redirect:/find/findpwd");
		}
		
	}
	
	@RequestMapping("/update")
	public ModelAndView update(String pwd) {
		System.out.println("甲方开具安居房就进度款加法看大家安静阿加解决就就kjj阶段空间加减速就就就就");
		System.out.println(annount);
		System.out.println(pwd);
		
		updatepwd.updatePwd(annount, pwd);
		return new ModelAndView("redirect:/login/index");
	}
	
	
	
}
